package io.itit.ecp.admin.provide.utils;

import io.itit.ecp.admin.common.constants.ParamConstants;
import io.itit.ecp.admin.provide.action.req.VisualizingQueryReq;
import io.itit.grass.common.provide.utils.ParamUtils;
import io.itit.grass.common.server.dto.ParamDto;
import io.itit.grass.common.server.utils.ConvertUtils;
import io.itit.grass.common.utils.Y666Utils;
import org.apache.commons.lang3.StringUtils;

public class VisParamUtils extends ParamUtils {

    /**
     * 计算同比的开始时间和结束
     *
     * @param req
     * @return
     */
    public static ParamDto calcPreSolidifyDate(VisualizingQueryReq req) {
        ParamDto dto = ConvertUtils.convert(req, ParamDto.class);
        dto.add(ParamConstants.SOLIDIFY_DATE_START, Y666Utils.addYearStr(req.getSolidifyDateStart(), -1));
        dto.add(ParamConstants.SOLIDIFY_DATE_END, Y666Utils.addYearStr(req.getSolidifyDateEnd(), -1));
        return dto;
    }

    /**
     * 新增年份
     *
     * @param dt
     * @param num
     * @return
     */
    public static String addYearStr(String dt, int num) {
        if (StringUtils.isEmpty(dt)) {
            return null;
        }
        return Y666Utils.addYearStr(dt, -1);
    }


}
